<template>
	<view class="main">
		<image src="../../static/img/logo.png" class="about_logo"></image>
		<view class="about_info t1">当前版本：{{version}}</view>
		<view class="tuic t2" v-show="news" @click="loads()">更新</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				token: '',
				type: '',
				version: '',
				upurl: '',
				news: false,
				des: '',
				plat: 0,
				isup: 0,
				brand:'',
				updateUrl:'market://details?id=com.vworld.zhaocaiami'
			}
		},
		onLoad() {
			var _this = this;
			_this.version=plus.runtime.version;
			// _this.version = '1.0.1'; //电脑端测试用
			uni.getStorage({
				key: 'user',
				success: function(res) {
					console.log('获取缓存：',res)
					_this.mainid = res.data.id;
					_this.gengxin();
				}
			});
			uni.getStorage({
				key: 'plat',
				success: function(res) {
					// _this.plat = res.data.plat;
					console.log(_this.plat);
				}
			});
			// 获取系统信息同步接口。
			// console.log((plus.runtime.version).split('.').join(''));
			
			// uni.getSystemInfo({
			// 	success: (res) => {
			// 		this.brand  = res.brand.toLowerCase()
			// 		this.setUpdateUrl()
			// 	}
			// })
		},
		methods: {
			setUpdateUrl(){
				switch (this.brand){
					case 'xiaomi':
					this.updateUrl = 'market://details?id=com.vworld.zhaocaiami'
						break;
					case 'huawei':
					this.updateUrl = ''
						break;
					case 'oppo':
					this.updateUrl = ''
						break;
					case 'vivo':
					this.updateUrl = ''
						break;
					default:
						break;
				}
			},
			gengxin() {
				uni.request({
					header: {
						'Content-Type': 'application/json', //自定义请求头信息
					},
					url: getApp().globalData.url + 'sys/getVersion', //仅为示例，并非真实接口地址。
					method: 'POST',
					data: {
						// id: this.mainid
						plat: this.plat, ///	平台（1：android；2：ios；3：微信；4：阿里）		true	string
						// id: this.mainid, ///	当前登录用户ID		false	string
						version: this.version ///	当前版本号
					},
					success: (res) => {
						uni.hideLoading(); //关闭加载动画
						console.log('检查更新：',res);
						if (res.data.status == '200') {
							this.isup = res.data.data.version.isUp; //是否强制升级
							this.version = res.data.data.version.version; //电脑端测试用
							this.upurl = res.data.data.version.url;
							if (res.data.data.up == 0) { //不升级
								uni.showToast({
									title: '当前是最新版本，不需要更新',
									icon: 'none',
									duration: 2000
								});
								this.news = false;
							} else {
								this.news = true;
							}
						} else {

							uni.showToast({
								title: res.data.msg,
								icon: 'none',
								duration: 2000
							});
						}
					},
					fail: (error) => {
						uni.hideLoading();
						// this.checks = true
						uni.showToast({
							title: error,
							icon: 'none',
							duration: 2000
						});
						console.log(error)
					}
				});
			},
			loads() {
				plus.runtime.openURL(this.updateUrl);
				
				// uni.showModal({ //提醒用户更新  
				// 	title: "更新提示",
				// 	content: this.version,
				// 	success: (res) => {
				// 		console.log(res);
				// 		if (res.confirm) {
				// 			plus.runtime.openURL(this.updateUrl);
				// 		} else {
				// 			if (this.isup == 1) {
				// 				plus.runtime.openURL(this.upurl);
				// 			}
				// 		}
				// 	}
				// })
				
			}
		}
	}
</script>
<style>
	image.about_logo {
		width: 24vw;
		height: 24vw;
		display: block;
		float: left;
		border-radius: 4vw;
		overflow: hidden;
		margin-top: 20vw;
		margin-left: 28vw;
		margin-bottom: 10vw;
	}

	.about_info {
		width: 100%;
		height: auto;
		display: block;
		float: left;
		line-height: 7vw;
	}

	/* 	.tuic {
		width: 100%;
		height: 14vw;
		display: block;
		float: left;
		text-align: center;
		line-height: 14vw;
		background: url(../../static/img/tuichu.png) no-repeat top center;
		background-size: 100%;
		margin-top: 30vw;
	} */
</style>
